<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="searchByCondition()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" @selection-change="handleSelectionChange" ref="checkTable" :row-key="handleReserve"
                      stripe highlight-current-row>
                <el-table-column type="selection" width="55" :reserve-selection='true' :selectable="selectable"></el-table-column>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="idCard" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center" sortable></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center" sortable></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="200">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini":disabled="scope.row.orderStatus != '未到诊'" @click="handleUpdate(scope.row)">确认预约</el-button>
                        <el-button size="mini" type="danger" :disabled="scope.row.orderStatus != '未到诊'" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div style="margin-top: 20px">
                <el-button type="primary" size="mini" @click="toggleSelection()" clearSelection>确认选中的预约</el-button>
                <el-button size="mini" type="danger" @click="toggleSelection2()">取消选中的预约</el-button>
            </div>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增" :visible.sync="dialogFormVisible" width="85%">
                    <el-container>
                        <el-aside width="350px">
                            <el-tabs  type="card">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="身份证" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="出生日期" prop="birthday">
                                                <el-col :span="22">
                                                    <el-date-picker type="date"
                                                                    placeholder="选择日期"
                                                                    format="yyyy 年 MM 月 dd 日"
                                                                    value-format="yyyy-MM-dd"
                                                                    v-model="formData.birthday"
                                                                    style="width: 100%;"></el-date-picker>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="性别" prop="sex">
                                                <el-radio-group v-model="formData.sex" size="medium">
                                                    <el-radio border label="1" >男</el-radio>
                                                    <el-radio border label="2" >女</el-radio>
                                                </el-radio-group>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="预约时间" prop="orderDate">
                                                <el-col :span="22">
                                                    <el-date-picker type="date"
                                                                    placeholder="选择日期"
                                                                    format="yyyy 年 MM 月 dd 日"
                                                                    value-format="yyyy-MM-dd"
                                                                    v-model="formData.orderDate"
                                                                    style="width: 100%;"></el-date-picker>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-form-item>
                                        <el-button type="primary" @click="handleAdd()">立即创建</el-button>
                                        <el-button @click="dialogFormVisible = false;">取消</el-button>
                                    </el-form-item>
                                </el-form>
                            </el-tabs>

                        </el-aside>
                        <el-main>
                            <div class="filter-container2">
                                <el-input placeholder="检测套餐" v-model="pagination2.queryString" style="width: 200px;"
                                          class="filter-item"></el-input>
                                <el-button @click="searchByCondition2()" class="dalfBut">查询</el-button>

                                <el-table size="small" current-row-key="id" :data="dataList2" ref="multipleTable" :row-key="handleReserve2"
                                          @selection-change="handleSelectionChange2" stripe highlight-current-row>
                                    <el-table-column type="selection" width="50"
                                                     :reserve-selection='true'></el-table-column>
                                    <el-table-column prop="name" label="套餐名称" align="center"></el-table-column>
                                    <el-table-column prop="sex" label="适用人群" align="center"></el-table-column>
                                    <el-table-column prop="remark" label="套餐介绍" align="center"></el-table-column>
                                </el-table>
                                <div class="pagination2-container">
                                    <el-pagination
                                            class="pagiantion2"
                                            @current-change="handleCurrentChange2"
                                            :current-page="pagination2.currentPage"
                                            :page-size="pagination2.pageSize"
                                            layout="total, prev, pager, next, jumper"
                                            :total="pagination2.total">
                                    </el-pagination>
                                </div>
                            </div>
                        </el-main>
                    </el-container>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null,//查询条件
            },
            pagination2: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 3,//每页显示的记录数
                total: 0,//总记录数
                queryString: null,//查询条件

            },
            dataList: [

            ],//当前页要展示的分页列表数据
            dataList2: [],

            formData: {
                /*name: '',
                idCard: '',
                birthday: '',
                phoneNumber: '',
                sex: '',
                age: '',
                orderDate: ''*/
            },//表单数据
            orderAndMemberIds: [],//预约列表分页查询数据id集合
            setmealIds: [],//预约列表新增弹窗分页查询数据id
            dialogFormVisible: false,//增加表单是否可见
            rules: {//校验规则
                name: [{required: true, message: '请输入姓名', trigger: 'blur'},
                    {min: 3, max: 10, message: '长度在 3 到 5 个字符', trigger: 'blur'}],
                idCard: [{required: true, message: '请输入身份证号', trigger: 'blur'},
                    {min: 15, max: 18, message: '请输入正确的身份证号', trigger: 'blur'}],
                phoneNumber: [{required: true, message: '请输入手机号', trigger: 'blur'},
                    {min: 11, max: 11, message: '请输入正确的手机号', trigger: 'blur'}],
                orderDate: [{required: true, message: '请选择预约日期', trigger: 'change'}],
                birthday: [{required: true, message: '请选择出生日期', trigger: 'change'}],
                sex: [{required: true, message: '请选择性别', trigger: 'change'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {

            //分页查询
            findPage() {
                //封装请求参数
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                axios.post("/orderList/findPage.do", param).then((res) => {
                    //解析Controller响应回的数据，为模型数据赋值
                    //处理日期类型参数格式
                    var datas = res.data.rows;
                    if (datas != null){
                     for (var i = 0; i < datas.length;i++){
                         var orderDateStr = datas[i].orderDate;
                         if (orderDateStr != null){
                             var orderDate = new Date(orderDateStr);
                             datas[i].orderDate = orderDate.getFullYear() + "-" +(orderDate.getMonth() + 1) +"-"+orderDate.getDate();
                         }
                     }
                    }
                    //给模型数据赋值
                    this.dataList = datas;
                    this.pagination.total = res.data.total;

                });
            },
            //搜索框查询
            searchByCondition(){
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //切换页码
            handleCurrentChange(currentPage){
                this.pagination.currentPage = currentPage;

                this.findPage();
            },
            //确定预约
            handleUpdate(row){
                // console.log(row);
                this.$confirm('是否确定预约?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求,确定预约
                    axios.post("/orderList/confirmOrder.do",row).then((res)=>{
                        if (res.data.flag){//操作成功
                            this.$message({
                                type: 'success',
                                message: res.data.message//'确定预约成功!'
                            });
                        } else {//操作失败
                           this.$message.error(res.data.message);
                        }
                    }).finally(()=>{
                        //重新分页查询
                        this.findPage();
                    });

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            //取消预约
            handleDelete(row){
                this.$confirm('是否取消预约?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求,确定预约
                    axios.post("/orderList/cancelOrder.do",row).then((res)=>{
                        if (res.data.flag){//操作成功
                            this.$message({
                                type: 'success',
                                message: res.data.message//'取消预约成功!'
                            });
                        } else {//操作失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(()=>{
                        //重新分页查询
                        this.findPage();
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
            //更改复选框
            handleSelectionChange(val){
                // console.log(val);
                this.orderAndMemberIds = val;
            },
            //确认选中的预约
            toggleSelection(){
                if (this.orderAndMemberIds == null || this.orderAndMemberIds.length === 0){

                    this.$message.error("未选择预约项");
                    return false;
                }
                // console.log(row);
                this.$confirm('是否确定选中的预约?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求,确定预约
                    axios.post("/orderList/multiConfirmOrder.do",this.orderAndMemberIds).then((res)=>{
                        if (res.data.flag){//操作成功
                            this.$message({
                                type: 'success',
                                message: res.data.message//'确定预约成功!'
                            });
                        } else {//操作失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(()=>{
                        //重新分页查询
                        this.findPage();
                        //清除选择的数据
                        this.$refs.checkTable.clearSelection();
                        this.orderAndMemberIds=[];
                    });

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });

            },
            //取消选择预约
            toggleSelection2(){
                if (this.orderAndMemberIds == null || this.orderAndMemberIds.length === 0){

                    this.$message.error("未选择预约项");
                    return false;
                }
                console.log(this.orderAndMemberIds);
                this.$confirm('是否取消选中的预约?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求,确定预约
                    axios.post("/orderList/multiCancelOrder.do",this.orderAndMemberIds).then((res)=>{
                        if (res.data.flag){//操作成功
                            this.$message({
                                type: 'success',
                                message: res.data.message//'确定预约成功!'
                            });
                        } else {//操作失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(()=>{
                        //重新分页查询
                        this.findPage();
                        //清除选择的数据
                        this.$refs.checkTable.cleanSelection();
                        this.orderAndMemberIds=[];
                    });

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },


            //重置表单
            resetForm() {
                this.setmealIds=[];
                this.formData = {};
                //重置套餐复选框
                this.$refs.multipleTable.clearSelection();
                //重置预约表单
                this.$refs['dataAddForm'].resetFields();
            },
            //弹出新建窗口
            handleCreate(){
                this.findPage2();
                //弹出新增窗口
                this.dialogFormVisible = true;
                //重置表单
                this.resetForm();
            },
            //新建窗口_分页查询
            findPage2(){
                //封装请求参数
                var param = {
                    currentPage: this.pagination2.currentPage,
                    pageSize: this.pagination2.pageSize,
                    queryString: this.pagination2.queryString
                };
                //发送ajax请求,获取套餐列表
                axios.post("/setmeal/findPage.do",param).then((res)=>{

                    this.dataList2=res.data.rows;
                    this.pagination2.total=res.data.total;
                });
            },
            //新建窗口_搜索框查询
            searchByCondition2(){
                this.pagination2.currentPage=1;
                this.findPage2();
            },
            //新建窗口_切换页码
            handleCurrentChange2(currentPage){
                this.pagination2.currentPage=currentPage;
                this.findPage2();
            },
            //新建窗口_改变复选框的状态
            handleSelectionChange2(val){
                if (val){//有选中套餐项
                    // console.log(val);
                    var ids = new Array();
                    for (var i=0;i<val.length;i++){
                        ids.push(val[i].id);
                    }
                    this.setmealIds = ids;
                } else {//没有选中套餐项
                    this.setmealIds=[];
                }
            },
            //新建窗口_添加新的预约
            handleAdd(){

                //判断是否已选套餐
                if (this.setmealIds == null || this.setmealIds.length == 0) {
                    this.$message.error("未选择套餐");
                    return false;
                }
                //表格校验
                this.$refs['dataAddForm'].validate((valid)=>{

                    if (valid){//通过表单校验
                        //发送ajax请求,添加新的预约
                        axios.post("/orderList/addOrderByTelephone.do?setmealIds="+ this.setmealIds,this.formData).then((res)=>{
                            if (res.data.flag){//预约成功
                                //关闭新增窗口
                                this.dialogFormVisible = false;
                                this.$message({
                                    message:res.data.message,
                                    type:"success"
                                });
                            } else {//预约失败
                                this.$message.error(res.data.message);
                            }
                        }).finally(()=>{
                            //预约界面刷新
                            this.findPage();
                        });

                    } else {//没有通过表单校验
                        this.$message.error("表单数据校验失败");
                    }
                })
            },


            //预约列表页面,复选框是否可以选中
            selectable(row, index){
                if(row.orderStatus !== '未到诊'){
                    return false;
                }else {
                    return true;
                }
            },
            //预约列表页面,保存已选择的复选框 ---分页更新后还在
            handleReserve(row){
                return row.id;
            },

            //新增页面,保存已选择的复选框 ---分页更新后还在
            handleReserve2(row){
                return row.id;
            }
        }
    })
</script>
</html>